package com.example.cloudtrade;

import android.os.Bundle;
import android.util.Log;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.example.cloudtrade.fragment.AddFragment;
import com.example.cloudtrade.fragment.CompareFragment;
import com.example.cloudtrade.fragment.FandFragment;
import com.example.cloudtrade.fragment.HomeFragment;
import com.example.cloudtrade.fragment.MeFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        BottomNavigationView bottomNav = findViewById(R.id.bottom_navigation);
        bottomNav.setOnItemSelectedListener(item -> {
            Fragment selectedFragment = null;
            int itemId = item.getItemId();
            if (itemId == R.id.nav_home) {
                selectedFragment = new HomeFragment();
            } else if (itemId == R.id.nav_discover) {
                selectedFragment = new FandFragment();
            } else if (itemId == R.id.nav_add) {
                selectedFragment = new AddFragment();
            } else if (itemId == R.id.nav_money) {
                selectedFragment = new CompareFragment();
            } else if (itemId == R.id.nav_profile) {
                selectedFragment = new MeFragment();
            }
            if (selectedFragment != null) {
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.container, selectedFragment)
                        .commit();

                Log.d("---", "onCreate: ");
            }
            return true;
        });
        // 默认显示首页
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.container, new HomeFragment())
                .commit();
    }
}